﻿#region 命名空间

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sharp.Domain.CMSBoundedContext.VIUModule.Aggregates;
using Sharp.Domain.Model;

#endregion

namespace Sharp.Domain.CMSBoundedContext.ModelConfigurations
{
    /// <summary>
    ///     Represents the entity type configuration for the <see cref="VIU" /> entity.
    /// </summary>
    public partial class VIUTypeConfiguration : EntityTypeConfiguration<VIU>
    {
        #region 构造函数

        /// <summary>
        ///     Initializes a new instance of <c>CustomerTypeConfiguration</c> class.
        /// </summary>
        public VIUTypeConfiguration()
        {
            HasKey(c => c.Id);

            Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity)
                .IsRequired();

            Property(t => t.CategoryId)

                .IsRequired();
            Property(t => t.Title)

                .HasMaxLength(100)
                .IsRequired();

            Property(t => t.Content)
                .IsMaxLength()
                .IsRequired();


            this.HasMany(t => t.Tags).WithMany(t => t.VIUs).Map(m =>
            {
                m.ToTable("CMS_TagVIURelation");
                m.MapLeftKey("TagId");
                m.MapRightKey("VIUId");
            });
            this.HasMany(t => t.Fields).WithMany(t => t.VIUs).Map(m =>
            {
                m.ToTable("CMS_FieldVIURelation");
                m.MapLeftKey("FieldId");
                m.MapRightKey("VIUId");
            });
            this.HasMany(t => t.Specials).WithMany(t => t.VIUs).Map(m =>
            {
                m.ToTable("CMS_SpecialVIURelation");
                m.MapLeftKey("SpecialId");
                m.MapRightKey("VIUId");
            });

            this.HasMany(t => t.MultiMedias).WithOptional(t => t.VIU).HasForeignKey(t => t.VIUId);
            this.HasMany(t => t.ApproveHistories).WithRequired(t => t.VIU).HasForeignKey(t => t.VIUId);
        }

        #endregion
    }
}